﻿using Newtonsoft.Json;

namespace Project.Core.Config.Entity.Dto {
    /// <summary>
    /// 多页查询实体类
    /// </summary>
    public class Page {
        /// <summary>
        /// 总数据量
        /// </summary>
        public int TotalItems = 0;

        /// <summary>
        /// 每页显示条数，默认 10
        /// </summary>
        public int Size = 10;

        /// <summary>
        /// 当前页
        /// </summary>
        public int Current = 1;

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages => (int)Math.Ceiling((decimal)TotalItems / Size);

        /// <summary>
        /// 分页构造函数
        /// </summary>
        /// <param name="current">当前页</param>
        /// <param name="size">每页显示条数</param>
        public Page(int current, int size) {
            this.Current = current;
            this.Size = size;
            this.TotalItems = 0;
        }

        /// <summary>
        /// 分页构造函数
        /// </summary>
        /// <param name="current"></param>
        /// <param name="size"></param>
        /// <param name="totalItems"></param>
        public Page(int current, int size, int totalItems) {
            this.Current = current;
            this.Size = size;
            this.TotalItems = totalItems;
        }

        public override string ToString() {
            return JsonConvert.SerializeObject(this);
        }
    }

    /// <summary>
    /// 多页查询实体类
    /// </summary>
    public class Page<T> : Page {
        /// <summary>
        /// 查询数据列表
        /// </summary>
        public IEnumerable<T> Records;
        public Page(int current, int size) : base(current, size) {
        }
        public Page(int current, int size, int totalItems) : base(current, size, totalItems) {
        }
    }
}
